package com.xiaobai.sequentialControl;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/*
要求必须先打印2后打印1
 */
@Slf4j
public class sequentialControlByParkUnPark {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            //如果线程2还没打印的话，那么就一直等待
            LockSupport.park();
            log.debug("执行....");
        }, "t1");
        Thread t2 = new Thread(() -> {
            log.debug("执行....");
            LockSupport.unpark(t1);
        }, "t2");
        t1.start();
        t2.start();
    }
}
